<!--项目库 列表组件 - modeB table列表-->
<template>
  <div class="list-wrap">
    <div class="list">
      <p class="tit">
        <span class="space"></span>
        <span class="No">序号</span>
        <span class="text-left">标题</span>
        <span class="text-left sp2">标准号</span>
        <span class="text-left sp1">标准类型</span>
        <span class="text-left sp1">发布日期</span>
        <span class="text-left sp1">标准状态</span>
        <span class="text-left">起草单位</span>
        <span class="text-left">起草人</span>
      </p>
      <ul class="context">
        <el-checkbox-group v-model="checkBoxList">
          <li
            v-for="(item, index) in this.listData"
            :key="index"
            @click="toDetail(item)"
          >
            <p class="space">
              <el-checkbox
                class="list-checkbox"
                :label="item"
                >{{
              }}</el-checkbox>
            </p>
            <p class="No">{{ index + 1 }}</p>
            <p
              class="pn-info text-left"
              v-html="item.title"
            ></p>
            <p class="ttl text-left sp2" v-html="item.code"></p>
            <p class="text-left sp1" v-html="item.type"></p>
            <p class="ipc text-left sp1" v-html="item.issue_date"></p>
            <p class="ttl text-left sp1" v-html="item.status"></p>
            <p class="ttl text-left">{{ (item.drafting_unit || []).join("、") }}</p>
            <p class="ttl text-left" v-html="item.draftsman"></p>
          </li>
        </el-checkbox-group>
      </ul>
      <!-- no-data -->
      <div v-if="noData" class="no-data">
        <loading1 :emptyText="emptyText" />
      </div>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
import { disassembleWord, wordsLight, isZh } from "@/utils/utils.js";
export default {
  props: {
    data: {
      type: Object,
    },
    emptyText: {
      type: String,
    },
    checkAllVal: {
      type: Boolean,
    },
  },
  data() {
    return {
      listData: [],
      origListData: [],
      checkBoxList: [],
      noData: false,
    };
  },
  computed: {
    ...mapState(["searchWord", "highlightModeSettings", "defaultTrans"]),
  },
  methods: {
    getListData(data, option = { needCollection: true }) {
      let result = data.result || [];
      let list = [];
      let origList = [];
      this.noData = false;
      result.forEach((v, index) => {
        let obj = {
          ...v,
          title: v.title || "-", // 标题
          tech_commitees: v.tech_commitees || "-", // 技术归口单位
          scope: v.scope, //领域
          industry_class: v.industry_class, //科技类别
          industry: v.industry, //产业类型
          issue_date: v.issue_date, //发行日期
          type: v.type || "--",
          draftsman: v?.draftsman?.join("、") || "--",
          id: v.id,
        };
        origList.push(obj);
      });
      this.origListData = origList;
      list = JSON.parse(JSON.stringify(origList)); // 高亮模式下的数据
      // 高亮模式
      let settings = [];
      let open = this.highlightModeSettings.open;
      // 默认关键词高亮样式
      let wordArr = disassembleWord(this.searchWord);
      let defObj = [];
      // let defObj = wordArr;
      if (open) {
        // 如果开启高亮模式
        settings = [...defObj, ...this.highlightModeSettings.modes];
      } else {
        settings = defObj;
      }
      list.forEach((v) => {
        v.title = wordsLight(v.title, settings);
      });

      this.listData = list;

      this.noData = origList.length <= 0 ? true : false;
    },

    // 跳转详情
    toDetail(item) {
      let detailLeftMenu = [];
      this.origListData.forEach((v) => {
        detailLeftMenu.push({
          id: v.id || "--", //
          title: v.title, // 标题号
        });
      });
      localStorage.setItem("detailLeftMenu", JSON.stringify(detailLeftMenu));
      this.$nextTick(() => {
        let routerUrl = this.$router.resolve({
          name: "DataCenterDetail",
          query: {
            id: item.esId,
            type: "standard",
          },
        });
        window.open(routerUrl.href, "_blank");
      });
    },
  },
  watch: {
    data() {
      this.getListData(this.data);
    },
    defaultTrans() {
      if (this.defaultTrans === true) {
        this.listData.forEach((v, i) => {
          v.showTitTrans = false; // 标题翻译
          this.transalte(v, i);
        });
      } else {
        this.listData.forEach((v, i) => {
          v.showTitTrans = true; // 标题翻译
          this.transalte(v, i);
        });
      }
    },
    // 高亮模式
    highlightModeSettings: {
      deep: true,
      handler: function () {
        this.getListData(this.data, { needCollection: false });
      },
    },
    // 多选
    checkBoxList() {
      this.$Bus.$emit("getDcCheckBoxlist", this.checkBoxList);
    },
    // 全选
    checkAllVal() {
      this.checkBoxList = this.checkAllVal ? this.listData : [];
    },
  },
  mounted() {
    this.getListData(this.data);
  },
};
</script>

<style lang="scss" scoped>
.list-wrap {
  position: relative;
  .list {
    position: relative;
    width: 100%;
    .tit {
      position: relative;
      display: flex;
      width: 100%;
      height: 41px;
      line-height: 41px;
      margin-top: 0;
      margin-bottom: 0;
      font-size: 14px;
      font-weight: bold;
      color: $color10;
      background-color: $color154;
      span {
        flex: 1;
        margin-right: 10px;
        text-align: center;
        font-size: 12px;
        &.space {
          flex: none;
          width: 35px;
        }
        &.No {
          flex: none;
          width: 40px;
          margin-right: 10px;
        }
      }
      .text-left {
        text-align: left;
      }
    }
    .context {
      position: relative;
      width: 100%;
      margin-top: 0;
      margin-bottom: 0;
      list-style: none;
      padding-left: 0;
      li {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 100%;
        min-height: 60px;
        border-bottom: 1px solid $color2;
        box-sizing: border-box;
        background-color: $color2 !important;
        &.no-data {
          background-color: #fff;
        }
        p {
          position: relative;
          flex: 1;
          line-height: 1.5;
          padding: 12px 0;
          margin-top: 0;
          margin-bottom: 0;
          margin-right: 10px;
          text-align: center;
          font-size: 12px;
          font-weight: 700;
          color: $color150;
          word-break: break-all;
          word-wrap: break-word;
          > span {
            font-size: 12px;
          }
          &:nth-of-type(1) {
            text-align: left;
          }
          &.space {
            flex: none;
            width: 35px;
            text-align: right;
            .list-checkbox {
              position: absolute;
              top: 2px;
              right: -7px;
              padding-left: 12px;
            }
          }
          &.No {
            flex: none;
            width: 40px;
            text-align: center;
            margin-right: 10px;
            color: $color6;
          }
          &.ttl {
            text-align: left;
            > span {
              cursor: pointer;
            }
          }
          &.ipc {
            text-align: left;
          }
          &.text-left {
            text-align: left;
          }
          .status {
            display: inline-block;
            min-width: 44px;
            line-height: 26px;
            border-radius: 3px;
            box-sizing: border-box;
            margin: 0 5px;
            font-size: 12px;
            font-weight: normal;
            color: $color2;
            background-color: $mainColor;
          }
        }
      }
    }
  }
}

.pn-info {
  position: relative;
  cursor: pointer;
  span {
    display: inline-block;
    min-height: 30px;
    line-height: 30px;
    margin-right: 5px;
    vertical-align: middle;
    cursor: pointer;
    &.icon {
      display: inline-block;
      width: 24px;
      margin-top: -2px;
      margin-right: 5px;
      text-align: center;
      font-weight: normal;
      font-size: 16px !important;
      cursor: pointer;
    }
    &.iconzhankai2 {
      margin-top: 0;
      font-size: 20px !important;
    }
    &.iconshoucang11 {
    }
    &.iconshoucang3 {
      color: $mainColor;
    }
  }
}
.sp1 {
  flex: none !important;
  width: 80px;
}
.sp2 {
  flex: none !important;
  width: 120px;
}
// .sp2 {
//   flex: none !important;
//   width: 14%;
//   min-width: 160px;
// }
.no-data {
  position: relative;
  line-height: 50px;
  text-align: center;
  font-size: 14px;
  color: $color6;
  background-color: $color2;
}
</style>